$(function () {
   $("#jqGrid").jqGrid({
        url: '../record/historyquerylist',
        datatype: "json",

        colModel: [			
			{ label: '标签编号', name: 'code_tag', width: 50},
			{ label: '人员名称', name: 'name_personnel', width: 80 }, 			
			{ label: '基站编号', name: 'code_station', width: 80 },
			{ label: '基站名称', name: 'name_station', width: 80 }, 			
	
			{ label: '触发时间', name: 'triggertime', width: 80 }, 			
			{ label: '最后时间', name: 'lasttime', width: 80 },
			{ label: '班次', name: 'id_shiftrangelist', width: 80 }
			,		
			{ label: '间隔时间', name: 'differenceTime', width: 80 }	,
			{ label: '间隔程度', name: 'differenceTimeType', width: 80,formatter: function(value, options, row){
				if(value=="1"){
					return '<div  class="class1" style="background-color:rgb(240,0,0)">';
				}
				if(value=="2"){
					return '<div  class="class1" style="background-color:rgb(180,0,0)">';
				}
				if(value=="3"){
					return '<div  class="class1" style="background-color:rgb(120,0,0)">';
				}
				if(value=="4"){
					return '<div  class="class1" style="background-color:rgb(60,0,0)">';
				}
				} }	
        ],
		viewrecords: true,
		 height: 'auto',
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "pageUtil.list",
            page: "pageUtil.currPage",
            total: "pageUtil.totalPage",
            records: "pageUtil.totalCount",
            repeatitems:false
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
	
});
var personlist;
var codeTag;

var search=document.getElementById("search");
search.onclick=function(){
	var page = $("#jqGrid").jqGrid('getGridParam','page');
	$("#jqGrid").jqGrid('setGridParam',{
		  postData:{'val':$("#val").val(),'dtFrom':$("#d4311").val(),'dtTo':$("#d4312").val()},
        page:page
    }).trigger("reloadGrid");
};

function searchPerson(){
	$.get("../record/personnelquerylist",{'val':$("#str").val()},function(r){
		personlist=r.list;
		var html;
		html='<tr><th>名称</th><th>身份证</th><th>联系方式</th><th>标签编号</th><th>组名</th></tr>';
		$.each(personlist,function(index,item){
			html+='<tr onclick="getCodeTag('+item.code_tag+')" data-dismiss="modal"><td>'+item.name+'</td><td>'+item.nric+'</td><td>'+item.contact+'</td><td>'+item.code_tag+'</td><td>'+item.group_name+'</td></tr>';
		});
		$("#personlist").html(html);
	});
}


function t(){  
    var val=$("#val").val(); //可以是一个可变的值  
    var dtFrom=$("#d4311").val(); //可以是一个可变的值  
    var dtTo=$("#d4312").val(); //可以是一个可变的值  
    
    document.getElementById("n").href="../record/export1?val="+val+"&dtFrom="+dtFrom+"&dtTo="+dtTo+"";
}
function getCodeTag(tag){
	var val=document.getElementById("val");
	val.value=tag;
}
